<?php
/**
 * Template Name: Page of Events
 *
 */
?>
<?php
    get_header(); 
    $mode = stripslashes($_GET["t"]);
    if ($mode != "future"):
      $mode = "past";
    endif;
?>
<section id="mainColumn">
	<h1><? echo ($mode=="past") ? "PAST ": "FUTURE ";?>EVENTS</h1>
	<?php 
	  $now 	= date_to_unixtime(date('m-d-Y'));
	 
	 
		$args = array(
		    'post_type' => 'event',
		    'meta_key' => 'event_time',
		    'meta_value' => $now,
		    'meta_compare' => ($mode == 'future')?'>=':'<',
		    'orderby' => 'meta_value',
		    'order' => ($mode == 'future')?'ASC':'DESC'
		);
	 
	$eventPosts = new WP_Query($args);

	$count = 0;
	if ($eventPosts->have_posts()):
	while($eventPosts->have_posts()):
	$eventPosts->the_post();
	if($count%2 ==0){
?>
	<div class="footer ">
		<div class="articles">
			<article class="floatLeft verticalLine horizontalHiddenLine">
				<h3>
					<?php the_title();?>
				</h3>
				<br />
				<p>
					<?php echo get_post_meta(get_the_ID(), 'event_ename', true); ?>
					<br /> When:
					<?php echo unixtime_to_date(get_post_meta(get_the_ID(), 'event_time', true)); ?>
					<br /> Where:
					<?php echo get_post_meta(get_the_ID(), 'event_location', true);?>
					<br /> What:
					<?php echo get_post_meta(get_the_ID(), 'event_description', true);?>
					<a id="teaserReadMore" href="<?php the_permalink(); ?>">Read more...</a>
				</p>
			</article>
			<?php }else {?>
			<article class="floatLeft">
				<h3>
					<?php the_title();?>
				</h3>
				<br />
				<p>
					<?php echo get_post_meta(get_the_ID(), 'event_ename', true); ?>
					<br /> When:
					<?php echo unixtime_to_date(get_post_meta(get_the_ID(), 'event_time', true)); ?>
					<br /> Where:
					<?php echo get_post_meta(get_the_ID(), 'event_location', true);?>
					<br /> What:
					<?php echo get_post_meta(get_the_ID(), 'event_description', true);?>
					<a id="teaserReadMore" href="<?php the_permalink(); ?>">Read more...</a>
				</p>
			</article>
		</div>
	</div>
	<?php }

	$count++;
	endwhile;
	else:
	  echo wpautop('Sorry, no events were found');
	endif;
	if($count%2==1){
	?>
	</div>
	</div>
	<article class="floatLeft">
		<h3></h3>
		<p>&nbsp;</p>
	</article>
	<?php	}	?>
	
</section>
<?php get_footer(); ?>
